<?php

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\service\R;
use app\common\model\StDept as StDeptModel;
use think\facade\Request;
use \app\common\model\StUser as StUserModel;
use \app\common\validate\StUser as StUserValidate;

class StUser extends Base
{
    /**同步用户数据
     * @param Request $request
     * @return array|bool|string|\think\response\Json|true|void
     */
    public function syncStUser(Request $request){
        $data = $request::getInput();
        $data = $this->twoDimensionalArray($data);
        // 验证
        $result = $this->validate($data[0], 'StUser');
        if(true !== $result) return $result;

        return (new StUserModel())->saveUserData($data);
    }


    public function deleteStUser(Request $request){
        if ($this->request->isDelete()) {
            $userId = $request::param('userCode');
            if($userId==null) R::error('请求参数异常');
            if (StUserModel::destroy(['user_code'=>$userId,'comid'=>COMID])) {
                return R::success();
            };
        }
        return R::error();
    }

}